package com.common.baselibrary;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

/**
 * 初始化Application
 */
public class ApplicationManager {

    private static Context application;
    private static Handler mainHandler;
    private static String ENVIRONMENT; //当前环境：生产环境 ／ 测试环境
    private static boolean needIgnoreHttpSSL = false;//Http请求是否忽略加密

    /**
     * Sets environment.
     *
     * @param ENVIRONMENT the environment
     */
    public static void setEnvironment(String ENVIRONMENT, boolean needIgnoreSSL) {
        ApplicationManager.ENVIRONMENT = ENVIRONMENT;
        ApplicationManager.needIgnoreHttpSSL = needIgnoreSSL;
    }

    /**
     * 获取当前环境
     */
    public static boolean isDebug() {
        return !"prd".equals(ENVIRONMENT);
    }

    /**
     * Http请求是否忽略加密
     */
    public static boolean needIgnoreHttpSSL() {
        return ApplicationManager.needIgnoreHttpSSL;
    }

    /**
     * Init.
     *
     * @param application the application
     */
    public static void init(Context application) {
        ApplicationManager.application = application;
    }

    /**
     * Gets application context.
     *
     * @return the application context
     */
    public static Context getApplicationContext() {
        return application;
    }

    /**
     * 获取主线成的handler，主线成唯一，维护消息队列的handler可以直接从这里，一般给bussiness层去使用
     *
     * @return handler
     */
    public static Handler getMainHandler() {
        if (mainHandler != null) {
            return mainHandler;
        }
        synchronized (ApplicationManager.class) {
            if (mainHandler == null) {
                mainHandler = new Handler(Looper.getMainLooper());
            }
        }
        return mainHandler;
    }


}
